<!doctype html>   <!--首页-->
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>Bootstrap 101 Template</title>
    <link rel="stylesheet" href="vendor/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="assets/css/common.css">
</head>
<body>
<!-- 顶部-->
<nav class="navbar navbar-default">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
                    data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="index.html">长乐未央</a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav">
                <li class="active"><a href="categories.html">视频课程 <span class="sr-only">(current)</span></a></li>
            </ul>
            <form class="navbar-form navbar-left">
                <div class="form-group">
                    <input type="text" class="form-control" placeholder="请填写搜索的课程">
                </div>
                <button type="submit" class="btn btn-default">搜索</button>
            </form>
        </div><!-- /.navbar-collapse -->
    </div><!-- /.container-fluid -->
</nav>

<!--轮播图-->
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
    <!-- Indicators -->
    <ol class="carousel-indicators">
        <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
        <li data-target="#carousel-example-generic" data-slide-to="1"></li>
    </ol>

    <!-- Wrapper for slides -->
    <div class="carousel-inner" role="listbox">
        <div class="item active">
            <a href="courses.html">
                <img src="https://images.clwy.cn/video/course/27/image/a9261f.jpg" alt="...">
                <div class="carousel-caption">
                    首页
                </div>
            </a>
        </div>
        <div class="item">
            <a href="courses.html">
                <img src="https://images.clwy.cn/video/course/10/image/2ede85.jpg" alt="...">
                <div class="carousel-caption">
                    其他也
                </div>
            </a>
        </div>
    </div>

    <!-- Controls -->
    <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
        <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
        <span class="sr-only">Previous</span>
    </a>
    <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
        <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
        <span class="sr-only">Next</span>
    </a>
</div>

<!--人气课程-->
<div class="container">
    <div class="page-header">
        <h1>人气课程 <small>Hot Courses</small></h1>
    </div>
    <div class="bs-example" data-example-id="media-alignment">


    </div>
</div>

<script src="vendor/jquery-3.6.0.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.min.js"></script>
<script>
    $(function () {
        /*  $.get("https://clwy.cn/api/v2/home.json",function (data){
             /!* console.log(data)*!/
              var i=data.popular_courses;
             var html =''
              for(var a=0 ;a<i.length;a++){
                  html+='  <div class="media">\n' +
                      '            <div class="media-left media-middle">\n' +
                      '                <a href="#">\n' +
                      '                    <img class="media-object" data-src="holder.js/64x64" alt="64x64"\n' +
                      '                         src="https://images.clwy.cn/video/course/10/image/2ede85.jpg!thumb" data-holder-rendered="true"\n' +
                      '                         style="width: 64px; height: 64px;">\n' +
                      '                </a>\n' +
                      '            </div>\n' +
                      '            <div class="media-body">\n' +
                      '                <h4 class="media-heading">'+i[a].name+'</h4>\n' +
                      '                <p>1111</p>\n' +
                      '            </div>\n' +
                      '        </div>'
              }
              var ul =$(".bs-example")
              ul.html(html)

          })*/

        $.get("https://clwy.cn/api/v2/home.json", function (data) {    //读取接口全部数据，存入data里面
            /* console.log(data)*/
            var popular_courses = data.popular_courses;               //获取接口中匹配对象popular_courses的数据
            var courses = ''                                         //定义一个内容为空的变量
            $.each(popular_courses, function (index, value) {          //数组循环，将数组中的每一项分别读取到，拼接成html
                courses += ' <div class="media">\n' +
                    '            <div class="media-left media-middle">\n' +
                    '                <a href="#">\n' +
                    '                    <img class="media-object" data-src="holder.js/64x64" alt="64x64"\n' +
                    '                         src=' + value.image + ' data-holder-rendered="true"\n' +
                    '                         style="width: 64px; height: 64px;">\n' +
                    '                </a>\n' +
                    '            </div>\n' +
                    '            <div class="media-body">\n' +
                    '                <h4 class="media-heading">' + value.name + '</h4>\n' +
                    '                <p>' + value.updated_at + '</p>\n' +
                    '            </div>\n' +
                    '        </div>'

            })
            /* console.log(courses)*/
            $('.bs-example').html(courses)                       //添加到html页面中

        })


    })
</script>
</body>
</html>
